package cn.zyjblogs.starter.mybatisplus.utils;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Sequence;

import java.net.InetAddress;

public class IdUtils {
    private static Sequence sequence;

    static {
        sequence = new Sequence(null);
    }

    public IdUtils() {
    }

    public IdUtils(InetAddress inetAddress) {
        IdUtils.sequence = new Sequence(inetAddress);
    }

    public IdUtils(long workerId, long dataCenterId) {
        IdUtils.sequence = new Sequence(workerId, dataCenterId);
    }

    public IdUtils(Sequence sequence) {
        IdUtils.sequence = sequence;
    }

    public static Long nextId(Object entity) {
        return sequence.nextId();
    }

    public static String nextId() {
        return nextId(null).toString();
    }

    public static String nextUUID(Object entity) {
        return IdWorker.get32UUID();
    }

    public static String nextUUID() {
        return IdWorker.get32UUID();
    }
}
